package nl.sweet.testsweet;

import junit.framework.TestResult;

/**
 * A wrapper for the results class for the unit test.
 * @author wessels
 */
public class TestSweetResult
{
	/** The class of the unit test. */
	private Class< ? extends TestSweetTestCase> _testClass;

	/** The time it took to perform the test. */
	private double _timeTaken;

	/** The TestResult object from JUnit. */
	private TestResult _testResult;

	private String _stdError;

	private String _stdOutput;

	/**
	 * Contructor.
	 * @param testClass The class of the test.
	 * @param stdError The output of the std error during the test.
	 * @param stdOutput The output of the std output during the test.
	 * @param timeTaken The time it took to perform the test.
	 * @param testResult The TestResult object from JUnit.
	 */
	public TestSweetResult(Class< ? extends TestSweetTestCase> testClass, String stdError,
			String stdOutput, double timeTaken, TestResult testResult)
	{
		_testClass = testClass;
		_stdError = stdError;
		_stdOutput = stdOutput;
		_timeTaken = timeTaken;
		_testResult = testResult;
	}

	/**
	 * Get the time it took to perform the test (in milliseconds).
	 * @return The time.
	 */
	public double getTimeTaken()
	{
		return _timeTaken;
	}

	/**
	 * Was the test succesfull?
	 * @return True if it was succesfull.
	 */
	public boolean isTestSuccesfull()
	{
		return _testResult.wasSuccessful();
	}
	
	/**
	 * Get the output on the std output during the test.
	 * @return The output;
	 */
	public String getOutput() {
		return _stdOutput;
	}
	
	/**
	 * Get the output on the std error during the test.
	 * @return The output;
	 */
	public String getError() {
		return _stdError;
	}

	/**
	 * Get the JUnit test result object.
	 * @return The test result object.
	 */
	public TestResult getTestResult()
	{
		return _testResult;
	}

	/**
	 * Get the name of the test case.
	 * @return The name of the test case.
	 */
	public String getTestCaseName()
	{
		try
		{
			return _testClass.newInstance().getTestName();
		}
		catch (InstantiationException e)
		{
			e.printStackTrace();
		}
		catch (IllegalAccessException e)
		{
			e.printStackTrace();
		}
		return null;
	}

	/**
	 * Get the class name of the test case.
	 * @return The class name.
	 */
	public String getClassName()
	{
		return _testClass.getName();
	}
}
